<?php
require_once("../inc/conn.php");
require_once("../inc/session.php");
//接收查询参数  姓名  和  性别
  
	 if(!empty($_GET["uname"])){
		$uname=$_GET["uname"]; 
	 }else{
		$uname="";
	 }
		
    if(!empty($_GET["sex"])){
		$sex=$_GET["sex"]; 
	 }else{
		$sex="";
	}
	  
	  //默认排序
	  if(!empty($_GET["px"])){
		$sort=$_GET["px"]; 
	 }else{
		$sort="desc";
	}
	 
	  
	  
	   if(!empty($_GET["page"])){
		$page=$_GET["page"]; 
	 }else{
		$page=1;
	}
	  
//实现翻页
	  
      
      //查询开始
       if($uname=="" && $sex==""){
		 $tsql = "select * from userinfo order by dt ".$sort; 
	  }
	  
	  
	  
	  //姓名为空
	  if($uname=="" && $sex!=""){
		 $tsql = "select * from userinfo where sex='".$sex."' order by dt ".$sort;
	  }
	  
	  //性别为空
	  if($uname!="" && $sex==""){
		 $tsql = "select * from userinfo where name like '%".$uname."%' order by dt ".$sort;
	  }
	  
	  //都不空
	  if($uname!="" && $sex!=""){
		 $tsql = "select * from userinfo where name like '%".$uname."%' and sex='".$sex."' order by dt ".$sort;
	  }



	 $trs=$conn->query($tsql);
	 

	  //获取记录总条数
	  $zongtiaoshu=$trs->num_rows;
	  $meiyeshu=10;
	  $zongyeshu= ceil($zongtiaoshu/$meiyeshu);
	  //echo $zongyeshu;
//当前是第几页
	  //记录的起始值  
	  $kaishi=($page-1)*$meiyeshu;

//查询开始
       if($uname=="" && $sex==""){
		 $sql = "select * from userinfo order by dt ".$sort." limit $kaishi,$meiyeshu"; 
	  }
	  
	  
	  
	  //姓名为空
	  if($uname=="" && $sex!=""){
		 $sql = "select * from userinfo where sex='".$sex."' order by dt ".$sort." limit $kaishi,$meiyeshu";
	  }
	  
	  //性别为空
	  if($uname!="" && $sex==""){
		 $sql = "select * from userinfo where name like '%".$uname."%' order by dt ".$sort." limit $kaishi,$meiyeshu";
	  }
	  
	  //都不空
	  if($uname!="" && $sex!=""){
		 $sql = "select * from userinfo where name like '%".$uname."%' and sex='".$sex."' order by dt ".$sort." limit $kaishi,$meiyeshu";
	  }


     $rs=$conn->query($sql);
?>
<!doctype html>
<html>
<meta charset="utf-8" />
<title>显示数据记录</title>
</head>

<body>

<form><table width="98%" border="1" align="center" cellpadding="5">
  <tbody>
    <tr>
      <td colspan="10" align="center">用户列表&nbsp; 【<a href="addinfo.php"> 写入信息</a> 】</td>
    </tr>
    <tr>
      <td colspan="10" align="right">姓名：
        <input name="uname" type="text" id="uname" size="20">
        &nbsp; 选择性别：
        <select name="sex" id="sex">
          <option selected="selected" value="">--选择性别--</option>
          <option value="女">女</option>
          <option value="男">男</option>
        </select>
        &nbsp; <input type="submit" name="submit3" id="submit3" formmethod="post"  formaction="seach.php" value="  立即查询  "></td>
    </tr>
    <tr>
      <td colspan="10" align="left">总共有<?php echo $zongyeshu?>页，总条数：<?php echo $zongtiaoshu;?>，当前记录是<?php echo $kaishi+1;?>-<?php if($zongtiaoshu<$page*$meiyeshu){echo $zongtiaoshu;}else{echo $page*$meiyeshu;}
	?></td>
    </tr>
    <tr>
      <td width="2%" align="center">&nbsp;</td>
      <td width="5%" align="center">序号</td>
      <td width="9%" align="center">所属部门</td>
      <td width="15%" align="center">姓名</td>
      <td width="8%" align="center">密码</td>
      <td width="10%" align="center">性别</td>
      <td width="16%" align="center">微信</td>
      <td width="9%" align="center">地址</td>
      <td width="14%" align="center">时间&nbsp; <a href="?px=asc">&nbsp;升序</a>&nbsp; &nbsp;<a href="?px=desc">降序</a></td>
      <td width="12%" align="center">操作</td>
    </tr>
	  
	<?php
	
	 //处理查询条件 
	  //两空
	  
	  
	  
//执行返回结果  
//获取返回结果的方式  数组方式来输出   MYSQL_BOTH 关联数组和索引数组  MYSQL_ASSOC 关联数组
//print_r($row);
//返回所有信息
	 
	  $i=0;
while ( $row = $rs->fetch_assoc() ) {
	$i++;
?> 
    <tr>
      <td align="center"><input name="sl[]" type="checkbox" id="sl[]" value="<?php echo $row[ "id" ];?>"></td>
      <td align="center"><?php echo $i;?></td>
      <td align="center">
		  
		  <?php 
	      $dsql="select * from department where id=".$row[ "sortid" ];
	      $drs=$conn->query($dsql);
	      $drow=$drs->fetch_assoc();
		  echo $drow["name"];
		  ?>
		
		
		</td>
      <td align="center">
        <input type="text" name="xm[]" id="xm" value="<?php echo $row[ "name" ];?>">
        <input type="text" hidden name="id[]" id="xm2" value="<?php echo $row[ "id" ];?>"></td>
      <td align="center"><?php echo $row[ "pass" ];?></td>
		<td align="center"><?php echo $row[ "sex" ];?></td>
      <td align="center">
        <input type="text" name="wx[]" id="wx" value="<?php echo $row[ "weixin" ];?>"></td>
      <td align="center"><?php echo $row[ "address" ];?></td>
      <td align="center"><?php echo $row[ "dt" ];?></td>
     
      <td align="center"><a href="edituser.php?id=<?php echo $row[ "id" ];?>">修改</a> &nbsp;<a href="deluser.php?id=<?php echo $row[ "id" ];?>">删除</a>&nbsp;</td>
    </tr>
	  
<?php
	}
?> 
	  
    <tr>
      <td colspan="10">
		<input name="submit4" type="button" id="qx" value="  全选  " onClick="quanxuan()">
        <input name="submit5" type="button" id="fx"  value="  反选  " onClick="fanxuan()">
		  
<input name="submit" type="submit" id="submit" formaction="delsluser.php" formmethod="POST" value="批量删除">
        <input type="submit" name="submit2" id="submit2" formaction="editsluser.php" formmethod="POST" value="批量更新">
        &nbsp; 
		  
		  <?php
		 if($page!=1){
		?>
		   <a href="?page=1&uname=<?php echo $uname;?>&sex=<?php echo $sex;?>">&nbsp;首页</a>
		  &nbsp; &nbsp; 
		  <a href="?page=<?php echo $page-1 ?>&uname=<?php echo $uname;?>&sex=<?php echo $sex;?>">上一页</a>
		  <?php
		 }
		  ?>
		 
		  
		    <?php
		 if($page!=$zongyeshu){
		?>
		  &nbsp; &nbsp; 
		  <a href="?page=<?php echo $page+1 ?>&uname=<?php echo $uname;?>&sex=<?php echo $sex;?>">下一页</a>
		  &nbsp; &nbsp; 
		  <a href="?page=<?php echo $zongyeshu;?>&uname=<?php echo $uname;?>&sex=<?php echo $sex;?>">尾页</a>
		 <?php
		 }
		  ?>
		
	&nbsp;	&nbsp;</td>
    </tr>
  </tbody>
</table></form>
	<script type="text/javascript">
	   function quanxuan（）{
		   
	   }
		
		function fanxuan（）{
		   
	   }
	</script>
</body>
</html>
